import { useState, useEffect } from 'react'

const useTime = (time) => {
    const [count, setCount] = useState(time);
    const [status, setStatus] = useState(true);
    useEffect(() => {
        let timer = null;
        timer = setTimeout(() => {
            if (count > 1) {
                setCount(count => count -= 1);
            } else {
                clearTimeout(timer);
                setStatus(status => status = false);
            }
        }, 1000)
        return () => clearTimeout(timer)
    }, [count])
    return [count, status]
}

export default useTime